sessionStorage.removeItem("phoneData");
/*设置保存草稿箱参数*/
var warehouseCode = "";//仓库code
var myWarehouseName = "";//仓库名称--用于判断指定仓
var inquiryWarehouseId = "";//询价单仓库id
var provinceId = "";  //配送省id
var cityId = "";  //配送城市id
var districtId = ""; //配送区id
var streetId = "" ; //配送街id
var provinceCode= "";  //配送省Code
var cityCode = "";  //配送城市Code
var districtCode = ""; //配送区Code
var streetCode = "" ; //配送街Code
var historyProvinceId = "";
var historyCityId = "";
var historyCountyId = "";
var historyVillageId = "";
var historyProvinceCode = "";
var historyCityCode = "";
var historyCountyCode = "";
var historyVillageCode = "";
var historyProvinceName = "请选择收货区域";   //历史省名称
var historyCityName = "";   //历史市名称
var historyDistrictName = "";  //历史县名称
var historyStreetName = "";   //历史乡名称
var tradeBoxItemsList = []; //商品列表
var purchaseCount = 0; //总数量
var totalMoney = 0; //总金额
var boxId = 0;
var customerId = '';
var inquiry_status = "";//询价单状态
var ship_add_id = "";//地址id
var out_of_stock = false; //是否存在缺货商品
$("#limitBox").hide();//可用额度隐藏
//清空列表
function clearTable() {
    $("#datatable tbody").html("");
    inquiry_status = "";
}
//无价格处理函数
function dealNullPrice(price,val) {
    if(price==null||price=="null"||price==""){
        return val;
    } else {
        return Number(price).toFixed(2);
    }
}
/*---------------------------------------------生成uuid开始去掉的参数----------------------------------------------------*/
function uuid() {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}
var labelUuid = uuid();
/*---------------------------------------------生成uuid结束----------------------------------------------------*/
sessionStorage.removeItem("isAlert");
if(sessionStorage.getItem("draftObj")){
    var draftObj = JSON.parse(sessionStorage.getItem("draftObj"));
    boxId = draftObj.boxId;
    $.ajax({
        contentType: 'application/json',
        url: root.replaceInter.replace_findTradeBoxItems ,
        cache: false, //禁用缓存
        type: "POST",
        data: JSON.stringify({
            "boxId":draftObj.boxId,//草稿箱id
            "provinceId":draftObj.provinceId,//配送省份id
            "createUserId":draftObj.createUserId,//创建人id
            "customerId":draftObj.customerId,//客户id
            "memberId":draftObj.memberId,
            "cityCode":draftObj.cityCode,
            "warehouseId":draftObj.warehouseId,
            // "warehouseId":1,
        }),
        success: function(data) {
            var dataObj = data;
            if(dataObj.errorCode == 0){
                /*渲染客户信息*/
                sessionStorage.removeItem("draftObj");
                sessionStorage.setItem("isAlert",1);
                if(myWarehouseName==""||myWarehouseName=="平行仓"||myWarehouseName==undefined||myWarehouseName=='undefined'){
                    warehouseCode = dataObj.tradeBox.warehouseId;
                }
                ship_add_id  = dataObj.tradeBox.addressId;
                historyProvinceCode = dataObj.tradeBox.provinceCode;
                historyCityCode = dataObj.tradeBox.cityCode;
                historyCountyCode = dataObj.tradeBox.districtCode;
                historyVillageCode = dataObj.tradeBox.streetCode;
                historyProvinceId = dataObj.tradeBox.provinceId;
                historyCityId = dataObj.tradeBox.cityId;
                historyCountyId = dataObj.tradeBox.districtId;
                historyVillageId = dataObj.tradeBox.streetId;
                provinceCode = dataObj.tradeBox.provinceCode;
                cityCode = dataObj.tradeBox.cityCode;
                districtCode = dataObj.tradeBox.districtCode;
                streetCode = dataObj.tradeBox.streetCode;
                provinceId = dataObj.tradeBox.provinceId;
                cityId = dataObj.tradeBox.cityId;
                districtId = dataObj.tradeBox.districtId;
                streetId = dataObj.tradeBox.streetId;
                $("#cusNameInfo").html(dataObj.tradeBox.customerName);
                $("#address").html(dataObj.tradeBox.custCompanyAddress);
                isCheck(dataObj.tradeBox.customerLoginAccount);//是否需要审核
                offenAddress(dataObj.tradeBox.memberId,JSON.stringify(data));//常用地址
                var user_data = {
                    customerName:"",
                    mobilePhone:"",
                    loginAccount:dataObj.tradeBox.customerLoginAccount
                }
                var succCallBack = function(data, status, response) {
                    if(data.errorCode ==0){
                        if(data.list.length == 0){
                            $.Huimodalalert("该用户没有下单账号",2000);
                        }else {
                            if(data.list[0].is_acc_period == '1'){
                                limit(data.list[0].customer_code);//可用额度
                                $("#limitBox").show();
                            }else {
                                $("#limitBox").hide();
                            }
                        }
                    }
                }
                web.doAjax(root.replaceInter.replace_adminQueryCustomerNameOrAccount, 'post', user_data, succCallBack);
                // limit(dataObj.tradeBox.customerCode);//可用额度
                $("#orderCode select").html('<option value="'+dataObj.tradeBox.memberId+'" data-code = "'+dataObj.tradeBox.customerCode+'" data-cusid = "'+dataObj.tradeBox.customerId+'" data-accounttype = "'+dataObj.tradeBox.account_type+'">'+dataObj.tradeBox.customerLoginAccount+'</option>');//账号
                // 渲染表格商品
                $("#datatable tbody").html("");
                var id = 0;
                for(var i=0;i<dataObj.tradeBoxItems.length;i++){
                    // 预计出货日计算
                    if(Number(dataObj.tradeBoxItems[i].actual_stock)>=Number(dataObj.tradeBoxItems[i].purchaseCount)){
                        var arrivalCycle = 1;
                    } else {
                        var arrivalCycle = Number(dataObj.tradeBoxItems[i].arrivalCycle)+1;
                    }
                    // 缺货数量计算
                    if(Number(dataObj.tradeBoxItems[i].stockNum)>=Number(dataObj.tradeBoxItems[i].purchaseCount)){
                        var littleNumber = "--";
                    }else {
                        var littleNumber = Number(dataObj.tradeBoxItems[i].purchaseCount)-Number(dataObj.tradeBoxItems[i].stockNum);
                    }
                    // 规格样式
                    var skuInfo = dealNull(dataObj.tradeBoxItems[i].skuInfo)+dealNull(dataObj.tradeBoxItems[i].color);
                    $("#datatable tbody").append('<tr>' +
                        '<td><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'" checked="checked"><span class="num">'+(id+1)+'</span></td>' +
                        '<td class="sku-code 1">'+dataObj.tradeBoxItems[i].skuCode+'</td>' +
                        '<td class="sku-name 2" onclick="goToGoodsDetail(this)">'+dataObj.tradeBoxItems[i].skuName+'</td>' +
                        '<td class="sku-info 3">'+skuInfo+'</td>' +
                        '<td class="origin 4" style="display: none;">'+dataObj.tradeBoxItems[i].origin+'</td>' +
                        '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+dataObj.tradeBoxItems[i].purchaseCount+'"></div></td>' +
                        '<td class="unit 6 ">'+dataObj.tradeBoxItems[i].unitName+'</td>' +
                        '<td class="parts-number 7">'+dataObj.tradeBoxItems[i].partsNumber+'</td>' +
                        '<td class="mini-order 8">'+dealNull(dataObj.tradeBoxItems[i].miniOrder,1)+'</td>' +
                        '<td class="sale-type 9">'+getSaleType(dataObj.tradeBoxItems[i].saleType)+'</td>' +
                        '<td class="price 10">'+dealNullPrice(dataObj.tradeBoxItems[i].salePrice,"-")+'</td>' +
                        '<td class="sub-total 11">'+(Number(dataObj.tradeBoxItems[i].subtotal)).toFixed(2)+'</td>' +
                        '<td class="actual-stock 12">'+dataObj.tradeBoxItems[i].stockNum+'</td>' +
                        '<td class="little-number 13">'+littleNumber+'</td>' +
                        '<td class="virtual-stock 14">'+dataObj.tradeBoxItems[i].virtualStock+'</td>' +
                        '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                        '<td class="warehouse-name 16">'+dataObj.tradeBoxItems[i].warehouseName+'</td>' +
                        '<td><a onClick="modaldemo(this)">删除</a></td>' +
                        '<td class="help-code 18" style="display:none;">'+dataObj.tradeBoxItems[i].helpcode.toUpperCase()+'</td>' +
                        '<td class="spu-id 19" style="display:none;">'+dataObj.tradeBoxItems[i].spuId+'</td>' +
                        '<td class="sku-id 20" style="display:none;">'+dataObj.tradeBoxItems[i].skuId+'</td>' +
                        '<td class="order-limit-type 21" style="display:none;">'+dataObj.tradeBoxItems[i].orderLimitType+'</td>' +
                        '<td class="arrival-cycle 22" style="display:none;">'+dealNull(dataObj.tradeBoxItems[i].arrivalCycle)+'</td>' +
                        '<td class="sale-type-code 23" style="display:none;">'+dealNull(dataObj.tradeBoxItems[i].saleType,"")+'</td>' +
                        '</tr>');
                    id+=1;
                }
                getGoodsDrafts();//获取草稿箱商品数据
                setTrRed("drafts",JSON.stringify(dataObj));//标红库存不足行
                // updataGoodsList(provinceCode);
                changeCount();//计数器
                getSelectLines();//计算购买数量和总金额
                isSelectAll();
                /*判断缺货数量是否为0，为0时标红*/
                var trArr = $("#datatable tr");
                for(var i=0;i<trArr.length;i++){
                    // 缺货数量
                    if($(trArr[i]).find(".little-number").html() > 0){
                        $(trArr[i]).find(".little-number")[0].style.color = "red";
                    }
                }
                for(var j=0;j<trArr.length;j++){
                    // 缺货数量
                    if($(trArr[j]).find(".little-number")[0].style.color == "red"){
                        $("#tableDiv").animate({scrollTop:$(trArr[j])[0].offsetTop},"fast");
                        return;
                    }
                }

            }else {
                sessionStorage.removeItem("draftObj");
                $.Huimodalalert(data.errorMessage,2000);
            }
        }
    });
}else {
    boxId = 0;
}
/*询价单接收数据*/
if(sessionStorage.getItem("inquiry_id")){
    $(".from_ask_price").removeClass("hide");
    $("#inquiry_id").html(sessionStorage.getItem("inquiry_id"));
    inquiry_status = sessionStorage.getItem("inquiry_status");
    switch (inquiry_status){
        case "10":
            $("#inquiryStatus").html("仅现货商品");
            break;
        case "20":
            $("#inquiryStatus").html("仅临采商品");
            break;
        case "30":
            $("#inquiryStatus").html("到货齐发");
            break;
    }
    $.ajax({
        /*'http://192.168.66.61:7120/ainquiry/inquiryDisposeTake'*/
        url: root.replaceInter.replace_inquiryDisposeTake,
        cache: false, //禁用缓存
        type: "POST",
        data: {
            inquiry_id:sessionStorage.getItem("inquiry_id"),
            classify:sessionStorage.getItem("inquiry_status"),
        },
        success: function(data) {
            var dataObj = data;
            if(dataObj.code == 0){
                $.ajax({
                    url: root.replaceInter.getAddressCorrespondWarehouse,
                    // url: 'https://'+ window.location.host +'/api/admin/abaseservice/area/getAddressCorrespondWarehouse',

                    cache: false, //禁用缓存
                    type: "POST",
                    data: {code:data.tradeBox.cityId},
                    success: function(data) {
                        if(data.errorCode == "0"){
                            if(myWarehouseName==""||myWarehouseName=="平行仓"||myWarehouseName==undefined||myWarehouseName=='undefined'){
                                warehouseCode = data.data.warehouse_code;
                            }

                        }else {
                            // $.Huimodalalert(data.errorMessage,2000);
                        }
                    }
                });
                /*渲染客户信息*/
                sessionStorage.setItem("isAlert",1);
                sessionStorage.removeItem("inquiry_id");
                sessionStorage.removeItem("inquiry_status");
                $("#cusNameInfo").html(dataObj.tradeBox.customerName);
                $("#address").html(dataObj.tradeBox.custCompanyAddress);
                isCheck(dataObj.tradeBox.customerLoginAccount);//是否需要审核
                offenAddress(dataObj.tradeBox.memberId,JSON.stringify(dataObj));//常用地址
                inquiryWarehouseId = dataObj.tradeBox.warehouse_code;
                if(myWarehouseName==""||myWarehouseName=="平行仓"||myWarehouseName==undefined||myWarehouseName=='undefined'){
                    warehouseCode = dataObj.tradeBox.warehouse_code;
                }
                ship_add_id  = dataObj.tradeBox.ship_add_id;
                var user_data = {
                    customerName:"",
                    mobilePhone:"",
                    loginAccount:dataObj.tradeBox.customerLoginAccount
                }
                var succCallBack = function(data, status, response) {
                    if(data.errorCode ==0){
                        if(data.list.length == 0){
                            $.Huimodalalert("该用户没有下单账号",2000);
                        }else {
                            if(data.list[0].is_acc_period == '1'){
                                limit(data.list[0].customer_code);//可用额度
                                $("#limitBox").show();
                            }else {
                                $("#limitBox").hide();
                            }
                        }
                    }
                }
                web.doAjax(root.replaceInter.replace_adminQueryCustomerNameOrAccount, 'post', user_data, succCallBack);
                // limit(dataObj.tradeBox.customerCode);//可用额度
                $("#orderCode select").html('<option value="'+dataObj.tradeBox.memberId+'" data-code = "'+dataObj.tradeBox.customerCode+'" data-cusid = "'+dataObj.tradeBox.customerId+'" data-accounttype = "'+dataObj.tradeBox.account_type+'">'+dataObj.tradeBox.customerLoginAccount+'</option>');//账号
                // 渲染表格商品
                $("#datatable tbody").html("");
                var id = 0;
                for(var i=0;i<dataObj.tradeBox.tradeBoxItems.length;i++){
                    if(dataObj.tradeBox.tradeBoxItems[i].helpcode==null){
                        helpcode="";
                    }else {
                        helpcode=dataObj.tradeBox.tradeBoxItems[i].helpcode.toUpperCase();
                    }
                    // 预计出货日计算
                    if(Number(dataObj.tradeBox.tradeBoxItems[i].mini_order)!=0&&Number(dataObj.tradeBox.tradeBoxItems[i].actual_stock)>=Number(dataObj.tradeBox.tradeBoxItems[i].purchaseCount)){
                        var arrivalCycle = 1;
                    } else {
                        var arrivalCycle = Number(dataObj.tradeBox.tradeBoxItems[i].arrival_cycle)+1;
                    }
                    // 缺货数量计算
                    if(Number(dataObj.tradeBox.tradeBoxItems[i].actual_stock)>=Number(dataObj.tradeBox.tradeBoxItems[i].purchaseCount)){
                        var littleNumber = "--";
                    }else {
                        var littleNumber = Number(dataObj.tradeBox.tradeBoxItems[i].purchaseCount)-Number(dataObj.tradeBox.tradeBoxItems[i].actual_stock);
                    }
                    // 规格样式
                    var skuInfo = dealNull(dataObj.tradeBox.tradeBoxItems[i].sale_attri_value)+dealNull(dataObj.tradeBox.tradeBoxItems[i].color);
                    $("#datatable tbody").append('<tr>' +
                        '<td><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'" checked="checked"><span class="num">'+(id+1)+'</span></td>' +
                        '<td class="sku-code 1">'+dataObj.tradeBox.tradeBoxItems[i].skuCode+'</td>' +
                        '<td class="sku-name 2" onclick="goToGoodsDetail(this)">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].name)+'</td>' +
                        '<td class="sku-info 3">'+skuInfo+'</td>' +
                        '<td class="origin 4" style="display: none;">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].origin)+'</td>' +
                        '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+dataObj.tradeBox.tradeBoxItems[i].purchaseCount+'"></div></td>' +
                        '<td class="unit 6">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].unit)+'</td>' +
                        '<td class="parts-number 7">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].parts_number)+'</td>' +
                        '<td class="mini-order 8">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].mini_order,1)+'</td>' +
                        '<td class="sale-type 9">'+getSaleType(dataObj.tradeBox.tradeBoxItems[i].sale_type)+'</td>' +
                        '<td class="price 10">'+(Number(dataObj.tradeBox.tradeBoxItems[i].salePrice)).toFixed(2)+'</td>' +
                        '<td class="sub-total 11">'+(Number(dataObj.tradeBox.tradeBoxItems[i].subtotal)).toFixed(2)+'</td>' +
                        '<td class="actual-stock 12">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].actual_stock)+'</td>' +
                        '<td class="little-number 13">'+littleNumber+'</td>' +
                        '<td class="virtual-stock 14">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].virtual_stock)+'</td>' +
                        '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                        '<td class="warehouse-name 16">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].warehouseName)+'</td>' +
                        '<td><a onClick="modaldemo(this)">删除</a></td>' +
                        '<td class="help-code 18" style="display:none;">'+helpcode+'</td>' +
                        '<td class="spu-id 19" style="display:none;">'+dataObj.tradeBox.tradeBoxItems[i].spuId+'</td>' +
                        '<td class="sku-id 20" style="display:none;">'+dataObj.tradeBox.tradeBoxItems[i].skuId+'</td>' +
                        '<td class="order-limit-type 21" style="display:none;">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].order_limit_type)+'</td>' +
                        '<td class="arrival-cycle 22" style="display:none;">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].arrival_cycle)+'</td>' +
                        '<td class="sale-type-code 23" style="display:none;">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].saleType,"")+'</td>' +
                        '</tr>');
                    id+=1;
                }
                getGoodsDrafts();//获取草稿箱商品数据
                setTrRed();//标红库存不足行
                changeCount();//计数器
                getSelectLines();//计算购买数量和总金额
                isSelectAll();
                /*判断缺货数量是否为0，为0时标红*/
                var trArr = $("#datatable tr");
                for(var i=0;i<trArr.length;i++){
                    // 缺货数量
                    if($(trArr[i]).find(".little-number").html() > 0){
                        $(trArr[i]).find(".little-number")[0].style.color = "red";
                    }
                }
                for(var j=0;j<trArr.length;j++){
                    // 缺货数量
                    if($(trArr[j]).find(".little-number")[0].style.color == "red"){
                        $("#tableDiv").animate({scrollTop:$(trArr[j])[0].offsetTop},"fast");
                        return;
                    }
                }
            }else {
                sessionStorage.removeItem("inquiry_id");
                // $.Huimodalalert(data.errorMessage,2000);
            }
        }
    });
}
/*订单接收数据*/
if(sessionStorage.getItem("order_id")){
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url:root.orderInter.orderTake,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify({
            orderId:sessionStorage.getItem("order_id"),
            memberId:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            loginAccount:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name

        }),
        /*data: {
            orderId:sessionStorage.getItem("order_id")
        },*/
        success: function(data) {
            var dataObj = data.data;
            if(data.errorCode == 0){
                /*渲染客户信息*/
                sessionStorage.setItem("isAlert",1);
                sessionStorage.removeItem("order_id");
                if(myWarehouseName==""||myWarehouseName=="平行仓"||myWarehouseName==undefined||myWarehouseName=='undefined'){
                    warehouseCode = dataObj.tradeBox.warehouse_code;
                }
                ship_add_id  = dataObj.tradeBox.address_id;
                $("#cusNameInfo").html(dataObj.tradeBox.customerName);
                $("#address").html(dataObj.tradeBox.custCompanyAddress);
                isCheck(dataObj.tradeBox.customerLoginAccount);//是否需要审核
                offenAddress(dataObj.tradeBox.memberId,0);//常用地址
                var user_data = {
                    customerName:"",
                    mobilePhone:"",
                    loginAccount:dataObj.tradeBox.customerLoginAccount
                }
                var succCallBack = function(data, status, response) {
                    if(data.errorCode ==0){
                        if(data.list.length == 0){
                            $.Huimodalalert("该用户没有下单账号",2000);
                        }else {
                            if(data.list[0].is_acc_period == '1'){
                                limit(data.list[0].customer_code);//可用额度
                                $("#limitBox").show();
                            }else {
                                $("#limitBox").hide();
                            }
                        }
                    }
                }
                web.doAjax(root.replaceInter.replace_adminQueryCustomerNameOrAccount, 'post', user_data, succCallBack);
                // limit(dataObj.tradeBox.customerCode);//可用额度
                $("#orderCode select").html('<option value="'+dataObj.tradeBox.memberId+'" data-code = "'+dataObj.tradeBox.customerCode+'" data-cusid = "'+dataObj.tradeBox.customerId+'" data-accounttype = "'+dataObj.tradeBox.account_type+'">'+dataObj.tradeBox.customerLoginAccount+'</option>');//账号
                // 渲染表格商品
                $("#datatable tbody").html("");
                var id = 0;
                for(var i=0;i<dataObj.tradeBox.tradeBoxItems.length;i++){
                    if (dataObj.tradeBox.tradeBoxItems[i].parts_number == 0){
                        partsNumber = "";
                    }else {
                        partsNumber = dataObj.tradeBox.tradeBoxItems[i].parts_number;
                    }
                    if (dataObj.tradeBox.tradeBoxItems[i].warehouse_name == null){
                        warehouse_name = "";
                    }else {
                        warehouse_name = dataObj.tradeBox.tradeBoxItems[i].warehouse_name;
                    }
                    if (dataObj.tradeBox.tradeBoxItems[i].helpcode == null){
                        helpcode = "";
                    }else {
                        helpcode = dataObj.tradeBox.tradeBoxItems[i].helpcode.toUpperCase();
                    }
                    // 预计出货日计算
                    if(Number(dataObj.tradeBox.tradeBoxItems[i].mini_order)!=0&&Number(dataObj.tradeBox.tradeBoxItems[i].actual_stock)>=Number(dataObj.tradeBox.tradeBoxItems[i].purchaseCount)){
                        var arrivalCycle = 1;
                    } else {
                        var arrivalCycle = Number(dataObj.tradeBox.tradeBoxItems[i].arrival_cycle)+1;
                    }
                    // 缺货数量计算
                    if(Number(dataObj.tradeBox.tradeBoxItems[i].actual_stock)>=Number(dataObj.tradeBox.tradeBoxItems[i].purchaseCount)){
                        var littleNumber = "--";
                    }else {
                        var littleNumber = Number(dataObj.tradeBox.tradeBoxItems[i].purchaseCount)-Number(dataObj.tradeBox.tradeBoxItems[i].actual_stock);
                    }
                    // 规格样式
                    var skuInfo = dealNull(dataObj.tradeBox.tradeBoxItems[i].sale_attri_value)+dealNull(dataObj.tradeBox.tradeBoxItems[i].color);
                    $("#datatable tbody").append('<tr>' +
                        '<td><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'" checked="checked"><span class="num">'+(id+1)+'</span></td>' +
                        '<td class="sku-code 1">'+dataObj.tradeBox.tradeBoxItems[i].skuCode+'</td>' +
                        '<td class="sku-name 2" onclick="goToGoodsDetail(this)">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].name)+'</td>' +
                        '<td class="sku-info 3">'+skuInfo+'</td>' +
                        '<td class="origin 4" style="display: none;">'+dataObj.tradeBox.tradeBoxItems[i].origin+'</td>' +
                        '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+dataObj.tradeBox.tradeBoxItems[i].purchaseCount+'"></div></td>' +
                        '<td class="unit 6">'+dataObj.tradeBox.tradeBoxItems[i].unit+'</td>' +
                        '<td class="parts-number 7">'+partsNumber+'</td>' +
                        '<td class="mini-order 8">'+dealNull(dataObj.mini_order,1)+'</td>' +
                        '<td class="sale-type 9">'+getSaleType(dataObj.tradeBox.tradeBoxItems[i].sale_type)+'</td>' +
                        '<td class="price 10">'+(Number(dataObj.tradeBox.tradeBoxItems[i].salePrice)).toFixed(2)+'</td>' +
                        '<td class="sub-total 11">'+(Number(dataObj.tradeBox.tradeBoxItems[i].subtotal)).toFixed(2)+'</td>' +
                        '<td class="actual-stock 12">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].actual_stock)+'</td>' +
                        '<td class="little-number 13">'+littleNumber+'</td>' +
                        '<td class="virtual-stock 14">'+dataObj.tradeBox.tradeBoxItems[i].virtual_stock+'</td>' +
                        '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                        '<td class="warehouse-name 16">'+warehouse_name+'</td>' +
                        '<td><a onClick="modaldemo(this)">删除</a></td>' +
                        '<td class="help-code 18" style="display:none;">'+helpcode+'</td>' +
                        '<td class="spu-id 19" style="display:none;">'+dataObj.tradeBox.tradeBoxItems[i].spuId+'</td>' +
                        '<td class="sku-id 20" style="display:none;">'+dataObj.tradeBox.tradeBoxItems[i].skuId+'</td>' +
                        '<td class="order-limit-type 21" style="display:none;">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].order_limit_type)+'</td>' +
                        '<td class="arrival-cycle 22" style="display:none;">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].arrival_cycle)+'</td>' +
                        '<td class="sale-type-code 23" style="display:none;">'+dealNull(dataObj.tradeBox.tradeBoxItems[i].saleType,"")+'</td>' +
                        '</tr>');
                    id+=1;
                }
                getGoodsDrafts();//获取草稿箱商品数据
                setTrRed();//标红库存不足行
                changeCount();//计数器
                getSelectLines();//计算购买数量和总金额
                isSelectAll();
                /*判断缺货数量是否为0，为0时标红*/
                var trArr = $("#datatable tr");
                for(var i=0;i<trArr.length;i++){
                    // 缺货数量
                    if($(trArr[i]).find(".little-number").html() > 0){
                        $(trArr[i]).find(".little-number")[0].style.color = "red";
                    }
                }
                for(var j=0;j<trArr.length;j++){
                    // 缺货数量
                    if($(trArr[j]).find(".little-number")[0].style.color == "red"){
                        $("#tableDiv").animate({scrollTop:$(trArr[j])[0].offsetTop},"fast");
                        return;
                    }
                }

            }else {
                sessionStorage.removeItem("inquiry_id");
                $.Huimodalalert(data.errorMessage,2000);
            }
        }
    });
    goDrafts();
}

function setTrRed(from,skuInfos) {
    /*判断库存是否为0，为0时标红*/
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        $(trArr[i]).css({
            background:"white"
        })
    }
    if(skuInfos){
        var searchResult = [];
        var datas = JSON.parse(skuInfos);
        var abnormalProducts = datas.abnormalProducts;
        for(var i=0;i<trArr.length;i++){
            if(abnormalProducts){
                for(var j=0;j<abnormalProducts.length;j++){
                    if($(trArr[i]).find(".sku-code").html() == abnormalProducts[j].skuCode){
                        trArr[i].style.background = "#ffe7e7";
                        if(abnormalProducts[j].code== 70){
                            searchResult.push(i);
                            $.Huimodalalert("商品价格变化",2000);
                            if(from&&from=="drafts"){
                                for(var k=0;k<datas.tradeBoxItems.length;k++){
                                    if(datas.tradeBoxItems[k].skuCode==abnormalProducts[j].skuCode){
                                        $(trArr[i]).find(".price").html(datas.tradeBoxItems[k].salePrice);
                                        $(trArr[i]).find(".actual-stock").html(datas.tradeBoxItems[k].stockNum);
                                        $(trArr[i]).find(".virtual-stock").html(datas.tradeBoxItems[k].virtualStock);
                                    }
                                }
                            }else {
                                for(var k=0;k<datas.skuModelList.length;k++){
                                    if(datas.skuModelList[k].skuCode==abnormalProducts[j].skuCode){
                                        $(trArr[i]).find(".price").html(datas.skuModelList[k].salePrice);
                                        $(trArr[i]).find(".actual-stock").html(datas.skuModelList[k].stockNum);
                                        $(trArr[i]).find(".virtual-stock").html(datas.skuModelList[k].virtualStock);
                                    }
                                }
                            }
                        }else {
                            searchResult.push(i);
                            console.log(searchResult)
                            if(from&&from=="drafts"){
                                for(var k=0;k<datas.tradeBoxItems.length;k++){
                                    if(datas.tradeBoxItems[k].skuCode==abnormalProducts[j].skuCode){
                                        $(trArr[i]).find(".actual-stock").html(abnormalProducts[j].tip);
                                        $(trArr[i]).find(".virtual-stock").html(datas.tradeBoxItems[k].virtualStock);
                                    }
                                }
                            }else {
                                for(var k=0;k<datas.skuModelList.length;k++){
                                    if(datas.skuModelList[k].skuCode==abnormalProducts[j].skuCode){
                                        $(trArr[i]).find(".actual-stock").html(abnormalProducts[j].tip);
                                        $(trArr[i]).find(".virtual-stock").html(datas.skuModelList[k].virtualStock);
                                    }
                                }
                            }

                            $(trArr[i]).find("td").find("input").removeAttr("checked");
                            $("#select-all-inp").attr("checked",false);
                            if(searchResult.length!=0){
                                $("#tableDiv").animate({scrollTop:$(trArr[searchResult[0]])[0].offsetTop},"fast"); //定位tr
                            }
                        }
                    }
                }
            }
        }
    }else {
        console.log("標紅")
        var searchResult = [];
        for(var i=0;i<trArr.length;i++){
            if(Number($(trArr[i]).find(".actual-stock").html())+Number($(trArr[i]).find(".virtual-stock").html()) <= 0 || Number($(trArr[i]).find(".count")[0].firstChild.lastChild.value) > Number($(trArr[i]).find(".actual-stock").html())+Number($(trArr[i]).find(".virtual-stock").html()) || $(trArr[i]).find(".actual-stock").html() == "无商品" || $(trArr[i]).find(".actual-stock").html() == "已下架"){
                searchResult.push(i);
                $(trArr[i]).find(".little-number").html("--")
                $(trArr[i]).css({
                    background:"#ffe7e7"
                });
                $(trArr[i]).find("td").find("input").removeAttr("checked");
                $("#select-all-inp").attr("checked",false);
            }
        }
        if(searchResult.length!=0){
            $("#tableDiv").animate({scrollTop:$(trArr[searchResult[0]])[0].offsetTop},"fast"); //定位tr
        }
    }
}
// 预计出货日
function arrivalCycle(thisEl) {
    if(Number($(thisEl.parentElement.parentElement.parentElement).find(".actual-stock").html())>=Number(thisEl.parentElement.lastChild.value)){
        $(thisEl.parentElement.parentElement.parentElement).find(".arrivalCycle").html(1);
    } else {
        $(thisEl.parentElement.parentElement.parentElement).find(".arrivalCycle").html(Number($(thisEl.parentElement.parentElement.parentElement).find(".arrival-cycle").html())+1);
    }
}
function changeCount() {
    /*计数器功能*/
    $(".number_increase").click(function () {
        this.parentElement.firstChild.style.background = "white";
        /*var trArr = $("#datatable tr");
        for(var i=0;i<trArr.length;i++){
            $(trArr[i]).css({
                background:"white"
            })
        }*/
        if(this.parentElement.lastChild.value<Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html())+Number($(this.parentElement.parentElement.parentElement).find(".virtual-stock").html())){
            if($(this.parentElement.parentElement.parentElement).find(".order-limit-type").html()==1){
                this.parentElement.lastChild.value = Number(this.parentElement.lastChild.value)+1;
                if(Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= this.parentElement.lastChild.value){
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html("--");
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
                }else {
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html(this.parentElement.lastChild.value - Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()));
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
                }
                arrivalCycle(this);
            }else {
                // 最小起订量和步长值判断
                if(this.parentElement.lastChild.value<(Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html())+Number($(this.parentElement.parentElement.parentElement).find(".virtual-stock").html()))-((Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html())+Number($(this.parentElement.parentElement.parentElement).find(".virtual-stock").html()))%Number($(this.parentElement.parentElement.parentElement).find(".mini-order").html()))){
                    this.parentElement.lastChild.value = Number(this.parentElement.lastChild.value)+Number($(this.parentElement.parentElement.parentElement).find(".mini-order").html());
                }else {
                    $(this.parentElement).find(".number_increase")[0].style.background = "#c3c3c3";
                }
                // this.parentElement.lastChild.value = Number(this.parentElement.lastChild.value)+Number($(this.parentElement.parentElement.parentElement).find(".mini-order").html());
                if(Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= this.parentElement.lastChild.value){
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html("--");
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
                }else {
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html(this.parentElement.lastChild.value - Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()));
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
                }
                arrivalCycle(this);
            }
        }else{
            $(this.parentElement).find(".number_increase")[0].style.background = "#c3c3c3";
            this.parentElement.lastChild.value = (Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html())+Number($(this.parentElement.parentElement.parentElement).find(".virtual-stock").html()))-((Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html())+Number($(this.parentElement.parentElement.parentElement).find(".virtual-stock").html()))%Number($(this.parentElement.parentElement.parentElement).find(".mini-order").html()));
            if(Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= this.parentElement.lastChild.value){
                $(this.parentElement.parentElement.parentElement).find(".little-number").html("--");
                $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
            }else {
                $(this.parentElement.parentElement.parentElement).find(".little-number").html(this.parentElement.lastChild.value - Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()));
                $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
            }
            arrivalCycle(this);
        }
        var thisCount = Number(this.parentElement.lastChild.value);//数量
        var thisPrice = Number($(this.parentElement.parentElement.parentElement).find(".price").html()); //单价
        subtotal(thisCount,thisPrice,this);//小计计算
        getSelectLines();//计算购买数量和总金额
        getGoodsDrafts();//获取草稿箱商品数据
    });
    $(".number_decrease").click(function () {
        if(Number(this.parentElement.lastChild.value) > Number($(this.parentElement.parentElement.parentElement).find(".mini-order").html())){
            this.parentElement.firstChild.style.background = "white";
            $(this.parentElement).find(".number_increase")[0].style.background = "white";
            if($(this.parentElement.parentElement.parentElement).find(".order-limit-type").html()==1){
                this.parentElement.lastChild.value = Number(this.parentElement.lastChild.value)-1;
                if(Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= this.parentElement.lastChild.value){
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html("--");
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
                }else {
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html(this.parentElement.lastChild.value - Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()));
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
                }
                arrivalCycle(this);
            }else {
                this.parentElement.lastChild.value = Number(this.parentElement.lastChild.value)-Number($(this.parentElement.parentElement.parentElement).find(".mini-order").html());
                if(Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= this.parentElement.lastChild.value){
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html("--");
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
                }else {
                    $(this.parentElement.parentElement.parentElement).find(".little-number").html(this.parentElement.lastChild.value - Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html()));
                    $(this.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
                }
                arrivalCycle(this);
            }
            if(this.parentElement.lastChild.value<=Number($(this.parentElement.parentElement.parentElement).find(".actual-stock").html())+Number($(this.parentElement.parentElement.parentElement).find(".virtual-stock").html())){
                var trArr = $("#datatable tr");
                for(var i=0;i<trArr.length;i++){
                    $(trArr[i]).css({
                        background:"white"
                    })
                }
            }
        }else {
            this.parentElement.firstChild.style.background = "#c3c3c3";
        }
        var thisCount = Number(this.parentElement.lastChild.value); //数量
        if($(this.parentElement.parentElement.parentElement).find(".price").html()=="-"){
            var thisPrice = 0;//单价
        } else {
            var thisPrice = Number($(this.parentElement.parentElement.parentElement).find(".price").html());//单价
        }
        subtotal(thisCount,thisPrice,this);//小计计算
        getSelectLines();//计算购买数量和总金额
        getGoodsDrafts();//获取草稿箱商品数据
    });
}
/*模糊查询客户名称列表*/
function getCustomer() {
    if ($("#customerName").val()==""){
        $("#customerUl").hide();
    }else {
        var user_data = {
            pageNum: 1,
            pageSize: 20,
            customerName: $("#customerName").val()
        }
        var succCallBack = function(data, status, response) {
            if(data.errorCode == "0") {
                if(data.list == null) {
                    classStr = "<li>无数据</li>"
                    $("#customerUl").html(classStr);
                } else {
                    var classStr = "";
                    for(var i = 0; i < data.list.length; i++) {
                        classStr += "<li onclick='selectName(\"" + data.list[i].customer_name + "\")'>" + data.list[i].customer_name + "</li>"
                    }
                    $("#customerUl").html(classStr);
                    $("#customerUl").show();
                }
            }
        }
        web.doAjax(root.replaceInter.replace_adminLenovoByCustomerName, 'post', user_data, succCallBack);
    }
}

$(document).bind("click", function(e) {
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#customerUl").length == 0 && $(e.target).closest("#customerName").length == 0) {
        //点击id为menu之外且id不是不是open，则触发
        $("#customerUl").hide()
    }
});
function selectName(name) {
    $("#customerName").val(name);
    $("#customerUl").hide();
}
/*获取下单账号*/
function getCode() {
    if ($("#code").val()==""){
        $("#codeUl").hide();
    }else {
        $("#codeUl").show();
        var user_data = {
            pageNum:1,
            pageSize:20,
            loginAccount:$("#code").val()
        }
        var succCallBack = function(data, status, response) {
            if(data.errorCode == "0") {
                if(data.list == null) {
                    classStr = "<li>无数据</li>"
                    $("#codeUl").html(classStr);
                } else {
                    var classStr = "";
                    for(var i = 0; i < data.list.length; i++) {
                        classStr += "<li onclick='selectCode(\"" + data.list[i].login_account + "\")'>" + data.list[i].login_account + "</li>"
                    }
                    $("#codeUl").html(classStr);
                    $("#codeUl").show();
                }
            }
        }
        web.doAjax(root.replaceInter.replace_adminLenovoByLoginAccount, 'post', user_data, succCallBack);
    }
}
function selectCode(code){
    $("#code").val(code);
    $("#codeUl").hide();
}
$(document).bind("click", function(e) {
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#codeUl").length == 0 && $(e.target).closest("#code").length == 0) {
        //点击id为menu之外且id不是不是open，则触发
        $("#codeUl").hide()
    }
});
/*根据客户名称、手机号、下单账号查询信息*/
function searchInfo1() {
    var user_data = {
        customerName:$("#customerName").val(),
        mobilePhone:$("#mobilePhone").val(),
        loginAccount:$("#code").val()
    }
    var succCallBack = function(data, status, response) {
        if(data.errorCode ==0){
            if(data.list.length == 0){
                $.Huimodalalert("该用户没有下单账号",2000);
            }else {
                $("#isNeedAuditList").html("");
                for(var i=0;i<data.list.length;i++){
                    $("#isNeedAuditList").append("<input type='hidden' id='needAudit"+data.list[i].member_id+"' value='"+data.list[i].neetAudit+"'>");
                }

                sessionStorage.setItem("isAlert",1);
                warehouseCode = data.list[0].warehouseCode;
                myWarehouseName = data.list[0].warehouseName;
                if(data.list[0].account_type==10||data.list[0].account_type==30){
                    $("#cusNameInfo").html(data.list[0].customer_name);
                    $("#address").html(data.list[0].address);
                } else {
                    $("#cusNameInfo").html(data.list[0].login_account);
                    $("#address").html("");
                }
                var optionStr = "";
                for(var i=0;i<data.list.length;i++){
                    optionStr += '<option  value="'+data.list[i].member_id+'" data-code = "'+data.list[i].customer_code+'" data-cusid = "'+data.list[i].customer_id+'" data-accounttype = "'+data.list[i].account_type+'" data-neetaudit = "'+data.list[i].neetAudit+'" data-all_author_single_user = "'+data.list[i].all_author_single_user+'" data-is_restrict = "'+data.list[i].is_restrict+'" data-is_acc_period = "'+data.list[i].is_acc_period+'" >'+data.list[i].login_account+ '</option>';
                }
                $("#orderCode select").html(optionStr);



                offenAddress($("#orderCode select").val(),0);//常用地址
                var accountType = $("#orderCode select").find("option:selected")[0].dataset.accounttype;
                if(accountType=='10'){
                    var is_restrict = $("#orderCode select").find("option:selected")[0].dataset.is_restrict;
                    console.log(is_restrict)
                    if(is_restrict=='1'){
                        $("#accountType").html("限制类客户");
                    }else if(is_restrict=='2'){
                        $("#accountType").html("正常客户");
                    }
                }else if(accountType==20||accountType==30){
                    $("#accountType").html("普通平台客户");
                }

                if($("#orderCode select").find("option:selected")[0].dataset.is_acc_period == 1){
                    limit($("#orderCode select").find("option:selected")[0].dataset.code);//可用额度
                    $("#limitBox").show();
                }else {
                    $("#limitBox").hide();
                }

                var el = $("#orderCode select").find("option:selected")[0].dataset.neetaudit;
                //是否需要审核
                if(accountType==10){
                    if (10 == el){
                        $("#isCheck").html("需要审批");
                    } else{
                        $("#isCheck").html("不需要审批");
                    }
                }else {
                    $("#isCheck").html("");
                }

            }
            customerId = data.list[0].customer_id;
        }
    }
    web.doAjax(root.replaceInter.replace_adminQueryCustomerNameOrAccount, 'post', user_data, succCallBack);
}
function searchInfo() {
    $("#accountType").html("");
    if($("#customerName").val()=="" && $("#mobilePhone").val()=="" && $("#code").val()==""){
        $.Huimodalalert("请检查客户信息是否填写完整",2000);
    }else {
        if(inquiry_status=="20"||inquiry_status=="30"){
            $("#change-customer").modal("show");
        }else {
            searchInfo1();
        }
    }
}
function changeSure() {
    inquiryWarehouseId = "";
    $(".from_ask_price").addClass("hide");
    $("#change-customer").modal("hide");
    clearTable();
    searchInfo1();
}
/*根据下单账号搜索客户信息*/
function isCheck(loginAccount) {
    var user_data = {
        loginAccount:loginAccount
    }
    var succCallBack = function(data, status, response) {
        if(data.errorCode ==0){
            if(data.list.length == 0){
                //$.Huimodalalert("该用户不存在",2000);
            }else {
                $("#isNeedAuditList").html("");
                for(var i=0;i<data.list.length;i++){
                    $("#isNeedAuditList").append("<input type='hidden' id='needAudit"+data.list[i].member_id+"' value='"+data.list[i].neetAudit+"'>");
                }

                sessionStorage.setItem("isAlert",1);
                if(data.list[0].account_type==10||data.list[0].account_type==30){
                    $("#cusNameInfo").html(data.list[0].customer_name);
                    $("#address").html(data.list[0].address);
                } else {
                    $("#cusNameInfo").html(data.list[0].login_account);
                    $("#address").html("");
                }

                var optionStr = "";
                for(var i=0;i<data.list.length;i++){
                    optionStr += '<option  value="'+data.list[i].member_id+'" data-code = "'+data.list[i].customer_code+'" data-cusid = "'+data.list[i].customer_id+'" data-accounttype = "'+data.list[i].account_type+'" data-neetaudit = "'+data.list[i].neetAudit+'" data-all_author_single_user = "'+data.list[i].all_author_single_user+'" data-is_restrict = "'+data.list[i].is_restrict+'" data-is_acc_period = "'+data.list[i].is_acc_period+'" >'+data.list[i].login_account+ '</option>';
                }
                $("#orderCode select").html(optionStr);
                //offenAddress($("#orderCode select").val(),0);//常用地址
                var accountType = $("#orderCode select").find("option:selected")[0].dataset.accounttype;
                if(accountType=='10'){
                    var is_restrict = $("#orderCode select").find("option:selected")[0].dataset.is_restrict;
                    if(is_restrict=='10'){
                        $("#accountType").html("正常客户");
                    }else if(is_restrict=='20'){
                        $("#accountType").html("限制类客户");
                    }
                }else if(accountType==20||accountType==30){
                    $("#accountType").html("普通平台客户");
                }

                if($("#orderCode select").find("option:selected")[0].dataset.is_acc_period == '1'&&accountType!=20&&accountType!=30){
                    $("#limitBox").show();
                    limit($("#orderCode select").find("option:selected")[0].dataset.code);//可用额度
                }

                var el = $("#orderCode select").find("option:selected")[0].dataset.neetaudit;
                //是否需要审核
                if(accountType==10){
                    if (10 == el){
                        $("#isCheck").html("需要审批");
                    } else{
                        $("#isCheck").html("不需要审批");
                    }
                }else {
                    $("#isCheck").html("");
                }

            }
            customerId = data.list[0].customer_id;
        }
    }
    web.doAjax(root.replaceInter.replace_adminQueryCustomerNameOrAccount, 'post', user_data, succCallBack);

}

/*可用额度查询*/
function limit(customerCode) {
    var user_data = {
        customerCode:customerCode
    }
    var succCallBack = function(data, status, response) {
        if(data.return_code ==0){
            $("#limit").html((data.favailable).toFixed(2));
            $("#limitBox").show();
        }else {
            $.Huimodalalert(data.return_msg,2000);
            $("#limit").html(0.00);
            $("#limitBox").hide();
        }
    }
    web.doAjax(root.replaceInter.replace_get_account_info, 'post', user_data, succCallBack);
}
/*常用地址查询*/
function offenAddress(val,draftData){
    provinceId = "";  //配送省id
    cityId = "";  //配送城市id
    districtId = ""; //配送区id
    streetId = "" ; //配送街id
    provinceCode= "";  //配送省Code
    cityCode = "";  //配送城市Code
    districtCode = ""; //配送区Code
    streetCode = "" ; //配送街Code
    historyProvinceId = "";
    historyCityId = "";
    historyCountyId = "";
    historyVillageId = "";
    historyProvinceCode = "";
    historyCityCode = "";
    historyCountyCode = "";
    historyVillageCode = "";
    if(draftData != 0){
        var dataObj = JSON.parse(draftData);
        historyProvinceCode = dataObj.tradeBox.provinceCode;
        historyCityCode = dataObj.tradeBox.cityCode;
        historyCountyCode = dataObj.tradeBox.districtCode;
        historyVillageCode = dataObj.tradeBox.streetCode;
        historyProvinceId = dataObj.tradeBox.provinceId;
        historyCityId = dataObj.tradeBox.cityId;
        historyCountyId = dataObj.tradeBox.districtId;
        historyVillageId = dataObj.tradeBox.streetId;
        provinceId = dataObj.tradeBox.provinceId;
        cityId = dataObj.tradeBox.cityId;
        districtId = dataObj.tradeBox.districtId;
        streetId = dataObj.tradeBox.streetId;
        historyProvinceName = dataObj.tradeBox.provinceName;
        historyCityName = dataObj.tradeBox.cityName;
        historyDistrictName = dataObj.tradeBox.districtName;
        historyStreetName = dataObj.tradeBox.streetName;

        $("#provinceName").html(dataObj.tradeBox.provinceName);
        provinceCode = dataObj.tradeBox.provinceCode;
        $("#cityName").html(dataObj.tradeBox.cityName);
        cityCode = dataObj.tradeBox.cityCode;
        $("#countyName").html(dataObj.tradeBox.districtName);
        districtCode = dataObj.tradeBox.districtCode;
        $("#villageName").html(dataObj.tradeBox.streetName);
        streetCode = dataObj.tradeBox.streetCode;
        var user_data = {
            pageNum:1,
            pageSize:20,
            memberId:val,
        }
        var succCallBack = function(data, status, response) {
            if (data.errorCode == 0) {
                if (data.list != null) {
                    /*常用地址渲染*/
                    var provinceName = "";
                    var cityName = "";
                    var areaName = "";
                    var streetName = "";
                    var detail_address = "";
                    if(data.list!=null ) {
                        if (data.list[0].provinceName != null) {
                            provinceName = data.list[0].provinceName;
                        } else {
                            provinceName = ""
                        }
                        if (data.list[0].cityName != null) {
                            cityName = data.list[0].cityName;
                        } else {
                            cityName = ""
                        }
                        if (data.list[0].areaName != null) {
                            areaName = data.list[0].areaName;
                        } else {
                            areaName = ""
                        }
                        if (data.list[0].streetName != null) {
                            streetName = data.list[0].streetName;
                        } else {
                            streetName = ""
                        }
                        if (data.list[0].detail_address != null) {
                            detail_address = data.list[0].detail_address;
                        } else {
                            detail_address = ""
                        }
                        $("#offenAddress").html(provinceName + cityName + areaName + streetName + detail_address);
                    }
                }
            }
        }
        web.doAjax(root.replaceInter.replace_adminGetCommonUseOrDefaultAddress, 'post', user_data, succCallBack);
    }else {
        var user_data = {
            pageNum:1,
            pageSize:20,
            memberId:val,
        }
        var succCallBack = function(data, status, response) {
            if(data.errorCode ==0){
                var vueBox = document.getElementById("vueBox");
                vueBox.style.display = "none";
                var notVueBox = document.getElementById("notVueBox");
                notVueBox.style.display = "block";
                $(".area_list").hide();
                var provinceName = "";
                var cityName = "";
                var areaName = "";
                var streetName = "";
                var detail_address = "";
                if(data.list!=null ){
                    if(myWarehouseName==""||myWarehouseName=="平行仓"||myWarehouseName==undefined||myWarehouseName=='undefined'){
                        warehouseCode = data.list[0].warehouse_code;
                    }
                    if(data.list[0].provinceName != null){
                        provinceName = data.list[0].provinceName;
                        provinceId = data.list[0].province_id;
                        provinceCode = data.list[0].province_code;
                        historyProvinceId = data.list[0].province_id;
                        historyProvinceCode = data.list[0].province_code;
                        historyProvinceName = data.list[0].provinceName;
                    }else {
                        provinceName = ""
                    }
                    if(data.list[0].cityName != null){
                        cityName = data.list[0].cityName;
                        historyCityId = data.list[0].city_id;
                        historyCityCode= data.list[0].city_code;
                        cityId = data.list[0].city_id;
                        cityCode = data.list[0].city_code
                        historyCityName = data.list[0].cityName;
                        updataGoodsList(cityCode);
                    }else {
                        cityName = ""
                    }
                    if(data.list[0].areaName != null){
                        areaName = data.list[0].areaName;
                        districtId = data.list[0].district_id;
                        districtCode = data.list[0].district_code;
                        historyCountyId = data.list[0].district_id;
                        historyCountyCode= data.list[0].district_code;
                        historyDistrictName = data.list[0].areaName;
                    }else {
                        areaName = ""
                    }
                    if(data.list[0].streetName != null){
                        streetName = data.list[0].streetName;
                        streetId = data.list[0].street_id;
                        streetCode = data.list[0].street_code;
                        historyVillageId = data.list[0].street_id;
                        historyVillageCode = data.list[0].street_code;
                        historyStreetName = data.list[0].streetName;
                    }else {
                        streetName = "";
                        streetId = 0;
                    }
                    if(data.list[0].detail_address != null){
                        detail_address = data.list[0].detail_address;
                    }else {
                        detail_address = ""
                    }

                    /*常用地址渲染*/
                    $("#offenAddress").html(provinceName+cityName+areaName+streetName+detail_address);
                    /*地址区域选择渲染*/
                    $("#provinceName").html(provinceName);
                    $("#cityName").html(cityName);
                    $("#countyName").html(areaName);
                    $("#villageName").html(streetName);
                } else {
                    var vueBox = document.getElementById("vueBox");
                    vueBox.style.display = "none";
                    var notVueBox = document.getElementById("notVueBox");
                    notVueBox.style.display = "block";
                    $("#offenAddress").html("");
                    $("#provinceName").html("请选择收货区域");
                    $("#cityName").html("");
                    $("#countyName").html("");
                    $("#villageName").html("");
                }
            }
        }
        web.doAjax(root.replaceInter.replace_adminGetCommonUseOrDefaultAddress, 'post', user_data, succCallBack);
        // web.doAjax('https://'+ window.location.host +'/api/admin/amembership/adminQueryAddressPerson', 'post', user_data, succCallBack);
    }
}
/*-----------------------------------------更新已选择商品库存信息开始---------------------------------------------------*/
function updataGoodsList(provinceIds,me,vueWarehouseCode) {
    if(me==1){
        $('html , body').animate({scrollTop: 0},'slow');
    }
    console.log(vueWarehouseCode)
    if(vueWarehouseCode){
        warehouseCode = vueWarehouseCode;
    }
    var tradeBoxItemsList = [];//校验商品列表请求的参数
    var trArr = $("#datatable tr");
    if(trArr.length != 0){
        for(var i=0;i<trArr.length;i++){
            tradeBoxItemsList.push({
                orderNumber: $(trArr[i]).find(".num")[0].innerHTML,
                skuCode: $(trArr[i]).find(".sku-code").html(),
                goodsNum: $(trArr[i]).find(".count").find(".numberbar").find("input").val(),//记录选择购买的数量
                areaId: provinceIds,
                customerId: $("#orderCode select").find("option:selected")[0].dataset.cusid,
                skuId: $(trArr[i]).find(".spu-id").html(),
                checkState: $(trArr[i]).find("td").find("input")[0].checked, //记录表格每行的选中状态
                warehouseCode:warehouseCode,
            });
        }
        $.ajax({
            contentType:"application/json",
            type: "POST",
            url: root.replaceInter.replace_getCustmerAreaChange,
            cache: false,  //禁用缓存
            dataType: "json",
            data: JSON.stringify(tradeBoxItemsList),
            success: function (data) {
                if(data.errorCode == 0){
                    if(data.unsale.length != 0){
                        for(var j=0;j<data.unsale.length;j++){
                            for(var i=0;i<data.list.length;i++){
                                if(data.list[i].sku_id == data.unsale[j].sku_id){
                                    data.list[i].actual_stock = "已下架";
                                    continue;
                                }
                            }
                        }

                    }
                    if(data.undata.length!=0){
                        for(var i=0;i<data.undata.length;i++){
                            for(var j=0;j<data.list.length;j++){
                                if(data.list[j].sku_id == data.undata[i].sku_id){
                                    data.list[j].actual_stock = "无商品";
                                    continue;
                                }

                            }
                        }
                    }
                    afterUpdataRenderTable(data.list);
                }else {
                    // console.log(data.errorMessage);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

            }
        });
    }
}
function afterUpdataRenderTable(goodsTr) {
    // 渲染表格商品
    $("#datatable tbody").html("");
    var id = 0;
    if(goodsTr!=null){
        for(var i=0;i<goodsTr.length;i++){
            // 表格节点字符串
            var partsNumber = "";
            var warehouse_name = "";
            var helpcode = "";
            var checkState = true;
            if (goodsTr[i].parts_number == null){
                partsNumber = "";
            }else {
                partsNumber = goodsTr[i].parts_number;
            }
            if (goodsTr[i].warehouse_name == null){
                warehouse_name = "";
            }else {
                warehouse_name = goodsTr[i].warehouse_name;
            }
            if (goodsTr[i].helpcode == null){
                helpcode = "";
            }else {
                helpcode = goodsTr[i].helpcode.toUpperCase();
            }
            // 预计出货日计算
            if(Number(goodsTr[i].actual_stock)>=Number(goodsTr[i].goodsNum)){
                var arrivalCycle = 1;
            } else {
                var arrivalCycle = Number(goodsTr[i].arrival_cycle)+1;
            }
            // 缺货数量计算
            if(Number(goodsTr[i].actual_stock)>=Number(goodsTr[i].goodsNum)){
                var littleNumber = "--";
            }else {
                var littleNumber = Number(goodsTr[i].goodsNum)-Number(goodsTr[i].actual_stock);
            }
            // 规格样式
            var skuInfo = dealNull(goodsTr[i].sale_attri_value)+dealNull(goodsTr[i].color);
            if (goodsTr[i].checkState == "true"){
                $("#datatable tbody").append('<tr>' +
                    '<td><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'" checked = ""><span class="num">'+(id+1)+'</span></td>' +
                    '<td class="sku-code 1">'+goodsTr[i].sku_code+'</td>' +
                    '<td class="sku-name 2" onclick="goToGoodsDetail(this)">'+dealNull(goodsTr[i].sku_name)+'</td>' +
                    '<td class="sku-info 3">'+skuInfo+'</td>' +
                    '<td class="origin 4" style="display: none;">'+dealNull(goodsTr[i].origin)+'</td>' +
                    '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+goodsTr[i].goodsNum+'"></div></td>' +
                    '<td class="unit 6">'+dealNull(goodsTr[i].unit)+'</td>' +
                    '<td class="parts-number 7">'+partsNumber+'</td>' +
                    '<td class="mini-order 8">'+dealNull(goodsTr[i].mini_order,1)+'</td>' +
                    '<td class="sale-type 9">'+getSaleType(goodsTr[i].sale_type)+'</td>' +
                    '<td class="price 10">'+dealNullPrice(goodsTr[i].sale_price,"-")+'</td>' +
                    '<td class="sub-total 11">'+(dealNullPrice(goodsTr[i].sale_price,0)*Number(goodsTr[i].goodsNum)).toFixed(2)+'</td>' +
                    '<td class="actual-stock 12">'+dealNull(goodsTr[i].actual_stock)+'</td>' +
                    '<td class="little-number 13">'+littleNumber+'</td>' +
                    '<td class="virtual_stock 14">'+dealNull(goodsTr[i].virtual_stock)+'</td>' +
                    '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                    '<td class="warehouse-name 16">'+warehouse_name+'</td>' +
                    '<td ><a onClick="modaldemo(this)">删除</a></td>' +
                    '<td class="help-code 18" style="display:none;">'+helpcode+'</td>' +
                    '<td class="spu-id 19" style="display:none;">'+goodsTr[i].spu_id+'</td>' +
                    '<td class="sku-id 20" style="display:none;">'+goodsTr[i].sku_id+'</td>' +
                    '<td class="order-limit-type 21" style="display:none;">'+dealNull(goodsTr[i].order_limit_type)+'</td>' +
                    '<td class="arrival-cycle 22" style="display:none;">'+dealNull(goodsTr[i].arrival_cycle)+'</td>' +
                    '<td style="display:none;" class="sale-type-code 23">'+dealNull(goodsTr[i].saleType,"")+'</td>' +
                    '</tr>');
            }else {
                $("#datatable tbody").append('<tr>' +
                    '<td ><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'"><span class="num">'+(id+1)+'</span></td>' +
                    '<td class="sku-code 1">'+goodsTr[i].sku_code+'</td>' +
                    '<td class="sku-name 2" onclick="goToGoodsDetail(this)">'+dealNull(goodsTr[i].sku_name)+'</td>' +
                    '<td class="sku-info 3">'+skuInfo+'</td>' +
                    '<td class="origin 4" style="display: none;">'+dealNull(goodsTr[i].origin)+'</td>' +
                    '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+goodsTr[i].goodsNum+'"></div></td>' +
                    '<td class="unit 6">'+dealNull(goodsTr[i].unit)+'</td>' +
                    '<td class="parts-number 7">'+partsNumber+'</td>' +
                    '<td class="mini-order 8">'+dealNull(goodsTr[i].mini_order,1)+'</td>' +
                    '<td class="sale-type 9">'+getSaleType(goodsTr[i].sale_type)+'</td>' +
                    '<td class="price 10">'+dealNullPrice(goodsTr[i].sale_price,"-")+'</td>' +
                    '<td class="sub-total 11">'+(dealNullPrice(goodsTr[i].sale_price,0)*Number(goodsTr[i].goodsNum)).toFixed(2)+'</td>' +
                    '<td class="actual-stock 12">'+dealNull(goodsTr[i].actual_stock)+'</td>' +
                    '<td class="little-number 13">'+littleNumber+'</td>' +
                    '<td class="virtual_stock 14">'+dealNull(goodsTr[i].virtual_stock)+'</td>' +
                    '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                    '<td class="warehouse-name 16">'+warehouse_name+'</td>' +
                    '<td ><a onClick="modaldemo(this)">删除</a></td>' +
                    '<td class="help-code 18" style="display:none;">'+helpcode+'</td>' +
                    '<td class="spu-id 19" style="display:none;">'+goodsTr[i].spu_id+'</td>' +
                    '<td class="sku-id 20" style="display:none;">'+goodsTr[i].sku_id+'</td>' +
                    '<td class="order-limit-type 21" style="display:none;">'+dealNull(goodsTr[i].order_limit_type)+'</td>' +
                    '<td class="arrival-cycle 22" style="display:none;">'+dealNull(goodsTr[i].arrival_cycle)+'</td>' +
                    '<td style="display:none;" class="sale-type-code 23">'+dealNull(goodsTr[i].saleType,"")+'</td>' +
                    '</tr>');
            }
            id+=1;
        }
    }
    getGoodsDrafts();//获取草稿箱商品数据
    setTrRed();//标红库存不足行
    changeCount();//计数器
    getSelectLines();//计算购买数量和总金额
    /*判断缺货数量是否为0，为0时标红*/
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        // 缺货数量
        if($(trArr[i]).find(".little-number").html() > 0){
            $(trArr[i]).find(".actual-stock")[0].style.color = "red";
        }
    }
    for(var j=0;j<trArr.length;j++){
        // 缺货数量
        if($(trArr[j]).find(".actual-stock")[0].style.color == "red"){
            $("#tableDiv").animate({scrollTop:$(trArr[j])[0].offsetTop},"fast");
            return;
        }
    }
}


/*-----------------------------------------更新已选择商品库存信息结束---------------------------------------------------*/
function getCustomerInfo(el) {
    if(inquiry_status&&inquiry_status!=20&&inquiry_status!=30){
        offenAddress(el.value,0); //常用地址
    }else if(!inquiry_status){
        offenAddress(el.value,0);
    }
    var isNeedAudit = $("#needAudit"+el.value).val();
    if (10 == isNeedAudit){
        $("#isCheck").html("需要审批");
    } else{
        $("#isCheck").html("不需要审批");
    }


    var accountType = $("#orderCode select").find("option:selected")[0].dataset.accounttype;
    if(accountType=='10'){
        var is_restrict = $("#orderCode select").find("option:selected")[0].dataset.is_restrict;
        if(is_restrict=='1'){
            $("#accountType").html("限制类客户");
        }else if(is_restrict=='2'){
            $("#accountType").html("正常客户");
        }
        $("#limitBox").show();
        limit($("#orderCode select").find("option:selected")[0].dataset.code);//可用额度
    }else if(accountType==20||accountType==30){
        $("#accountType").html("普通平台客户");
    }
}
/*sale_type
10 指定展示价
20 指定交易价
30 指定展示价和指定交易价
40 批发价
50 分销价*/
// 指定价判断
function getSaleType(saleTypeCode) {
    switch (saleTypeCode){
        case 10:
            return "指定展示价"
            break;
        case 20:
            return "指定交易价"
            break;
        case 30:
            return "指定展示价和指定交易价"
            break;
        case 40:
            return "批发价"
            break;
        case 50:
            return "分销价"
            break;
        default:
            return ""
            break;
    }
}
/*渲染table列表*/
function renderTable(delInfo){
    //delInfo为true时，时执行删除操作后的数据,为false时，是执行添加商品操作后的数据
    // 渲染表格商品
    $("#datatable tbody").html("");
    var id = 0;
    if(delInfo == false){
        var goodsTr = JSON.parse(sessionStorage.getItem("goodsTr"));
        console.log(goodsTr)
        var id = $("#datatable tbody").find("tr").length;
        for(var i=0;i<goodsTr.length;i++){
            // 预计出货日计算
            if(Number(goodsTr[i].actual_stock)>=Number(goodsTr[i].count)){
                var arrivalCycle = 1;
            } else {
                var arrivalCycle = Number(goodsTr[i].arrival_cycle)+1;
            }
            // 缺货数量计算
            if(Number(goodsTr[i].actual_stock)>=Number(goodsTr[i].count)){
                var littleNumber = "--";
            }else {
                var littleNumber = Number(goodsTr[i].count)-Number(goodsTr[i].actual_stock);
            }
            // 规格样式

            var skuInfo = dealNull(goodsTr[i].sale_attri_value)+dealNull(goodsTr[i].color);
            $("#datatable tbody").append('<tr>' +
                '<td ><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'" checked = "'+goodsTr[i].checkedState+'"><span class="num">'+(id+1)+'</span></td>' +
                '<td class="sku-code 1">'+dealNull(goodsTr[i].sku_code)+'</td>' +
                '<td onclick="goToGoodsDetail(this)" class="sku-name 2">'+dealNull(goodsTr[i].sku_name)+'</td>' +
                '<td class="sku-info 3">'+skuInfo+'</td>' +
                '<td style="display: none;" class="origin 4">'+dealNull(goodsTr[i].origin)+'</td>' +
                '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+goodsTr[i].count+'"></div></td>' +
                '<td class="unit 6">'+dealNull(goodsTr[i].unit)+'</td>' +
                '<td class="parts-number 7">'+dealNull(goodsTr[i].parts_number)+'</td>' +
                '<td class="mini-order 8">'+dealNull(goodsTr[i].mini_order,1)+'</td>' +
                '<td class="sale-type 9">'+getSaleType(goodsTr[i].saleType)+'</td>' +
                '<td class="price 10">'+(Number(goodsTr[i].price)).toFixed(2)+'</td>' +
                '<td class="sub-total 11">'+(Number(goodsTr[i].price)*Number(goodsTr[i].count)).toFixed(2)+'</td>' +
                '<td class="actual-stock 12">'+goodsTr[i].actual_stock+'</td>' +
                '<td class="little-number 13">'+littleNumber+'</td>' +
                '<td class="virtual-stock 14">'+goodsTr[i].virtual_stock+'</td>' +
                '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                '<td class="warehouse-name 16">'+dealNull(goodsTr[i].warehouse_name)+'</td>' +
                '<td><a onClick="modaldemo(this)">删除</a></td>' +
                '<td style="display:none;" class="help-code 18">'+dealNull(goodsTr[i].helpcode).toUpperCase()+'</td>' +
                '<td style="display:none;" class="spu-id 19">'+dealNull(goodsTr[i].spu_id)+'</td>' +
                '<td style="display:none;" class="sku-id 20">'+dealNull(goodsTr[i].sku_id)+'</td>' +
                '<td style="display:none;" class="order-limit-type 21">'+dealNull(goodsTr[i].order_limit_type)+'</td>' +
                '<td style="display:none;" class="arrival-cycle 22">'+dealNull(goodsTr[i].arrival_cycle)+'</td>' +
                '<td style="display:none;" class="sale-type-code 23">'+dealNull(goodsTr[i].saleType,"")+'</td>' +
                '</tr>');
            id+=1;
        }
    }else {
        var goodsTr = delGoodsTr;
        console.log(goodsTr)
        id = 0;
        for(var i=0;i<goodsTr.length;i++){
            // 预计出货日计算
            if(Number(goodsTr[i].actual_stock)>=Number(goodsTr[i].count)){
                var arrivalCycle = 1;
            } else {
                var arrivalCycle = Number(goodsTr[i].arrival_cycle)+1;
            }
            // 缺货数量计算
            if(Number(goodsTr[i].actual_stock)>=Number(goodsTr[i].count)){
                var littleNumber = "--";
            }else {
                var littleNumber = Number(goodsTr[i].count)-Number(goodsTr[i].actual_stock);
            }
            // 规格样式
            var skuInfo = dealNull(goodsTr[i].sale_attri_value)+dealNull(goodsTr[i].color);
            if(goodsTr[i].checkedState){
                $("#datatable tbody").append('<tr>' +
                    '<td><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'" checked = "'+goodsTr[i].checkedState+'"><span class="num">'+(id+1)+'</span></td>' +
                    '<td class="sku-code 1">'+dealNull(goodsTr[i].sku_code)+'</td>' +
                    '<td class="sku-name 2" onclick="goToGoodsDetail(this)">'+dealNull(goodsTr[i].sku_name)+'</td>' +
                    '<td class="sku-info 3">'+skuInfo+'</td>' +
                    '<td class="origin 4" style="display: none;">'+dealNull(goodsTr[i].origin)+'</td>' +
                    '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+goodsTr[i].count+'"></div></td>' +
                    '<td class="unit 6">'+dealNull(goodsTr[i].unit)+'</td>' +
                    '<td class="parts-number 7">'+dealNull(goodsTr[i].parts_number)+'</td>' +
                    '<td class="mini-order 8">'+dealNull(goodsTr[i].mini_order,1)+'</td>' +
                    '<td class="sale-type 9">'+getSaleType(goodsTr[i].saleType)+'</td>' +
                    '<td class="price 10">'+(Number(goodsTr[i].price)).toFixed(2)+'</td>' +
                    '<td class="sub-total 11">'+(Number(goodsTr[i].price)*Number(goodsTr[i].count)).toFixed(2)+'</td>' +
                    '<td class="actual-stock 12">'+dealNull(goodsTr[i].actual_stock)+'</td>' +
                    '<td class="little-number 13">'+littleNumber+'</td>' +
                    '<td class="virtual-stock 14">'+goodsTr[i].virtual_stock+'</td>' +
                    '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                    '<td class="warehouse-name 16">'+dealNull(goodsTr[i].warehouse_name)+'</td>' +
                    '<td><a onClick="modaldemo(this)">删除</a></td>' +
                    '<td class="help-code 18" style="display:none;">'+dealNull(goodsTr[i].helpcode).toUpperCase()+'</td>' +
                    '<td class="spu-id 19" style="display:none;">'+dealNull(goodsTr[i].spu_id)+'</td>' +
                    '<td class="sku-id 20" style="display:none;">'+dealNull(goodsTr[i].sku_id)+'</td>' +
                    '<td class="order-limit-type 21" style="display:none;">'+dealNull(goodsTr[i].order_limit_type)+'</td>' +
                    '<td class="arrival-cycle 22" style="display:none;">'+dealNull(goodsTr[i].arrival_cycle)+'</td>' +
                    '<td class="sale-type-code 23" style="display:none;">'+dealNull(goodsTr[i].saleType,"")+'</td>' +
                    '</tr>');
            }else {
                $("#datatable tbody").append('<tr>' +
                    '<td><input class="spuId" onchange="selectThis(this)" type="checkbox" name="spuId" value="'+i+'"><span class="num">'+(id+1)+'</span></td>' +
                    '<td class="sku-code 1">'+dealNull(goodsTr[i].sku_code)+'</td>' +
                    '<td class="sku-name 2" onclick="goToGoodsDetail(this)">'+dealNull(goodsTr[i].sku_name)+'</td>' +
                    '<td class="sku-info 3">'+skuInfo+'</td>' +
                    '<td class="origin 4" style="display: none;">'+dealNull(goodsTr[i].origin)+'</td>' +
                    '<td class="count 5"><div class="numberbar"><span class="number_decrease">-</span><span class="number_increase">+</span><input type="text" oninput="checkCount(this)" class="num_text" value="'+goodsTr[i].count+'"></div></td>' +
                    '<td class="unit 6">'+dealNull(goodsTr[i].unit)+'</td>' +
                    '<td class="parts-number 7">'+dealNull(goodsTr[i].parts_number)+'</td>' +
                    '<td class="mini-order 8">'+dealNull(goodsTr[i].mini_order,1)+'</td>' +
                    '<td class="sale-type 9">'+getSaleType(goodsTr[i].saleType)+'</td>' +
                    '<td class="price 10">'+(Number(goodsTr[i].price)).toFixed(2)+'</td>' +
                    '<td class="sub-total 11">'+(Number(goodsTr[i].price)*Number(goodsTr[i].count)).toFixed(2)+'</td>' +
                    '<td class="actual-stock 12">'+dealNull(goodsTr[i].actual_stock)+'</td>' +
                    '<td class="little-number 13">'+littleNumber+'</td>' +
                    '<td class="virtual-stock 14">'+goodsTr[i].virtual_stock+'</td>' +
                    '<td class="arrivalCycle 15">'+arrivalCycle+'</td>' +
                    '<td class="warehouse-name 16">'+dealNull(goodsTr[i].warehouse_name)+'</td>' +
                    '<td><a onClick="modaldemo(this)">删除</a></td>' +
                    '<td class="help-code 18" style="display:none;">'+dealNull(goodsTr[i].helpcode).toUpperCase()+'</td>' +
                    '<td class="spu-id 19" style="display:none;">'+dealNull(goodsTr[i].spu_id)+'</td>' +
                    '<td class="sku-id 20" style="display:none;">'+dealNull(goodsTr[i].sku_id)+'</td>' +
                    '<td class="order-limit-type 21" style="display:none;">'+dealNull(goodsTr[i].order_limit_type)+'</td>' +
                    '<td class="arrival-cycle 22" style="display:none;">'+dealNull(goodsTr[i].arrival_cycle)+'</td>' +
                    '<td class="sale-type-code 23" style="display:none;">'+dealNull(goodsTr[i].saleType,"")+'</td>' +
                    '</tr>');
            }
            id+=1;
        }
    }
    getGoodsDrafts();//获取草稿箱商品数据
    setTrRed();//标红库存不足行
    changeCount();//计数器
    getSelectLines();//计算购买数量和总金额
    isSelectAll();
    /*判断缺货数量是否为0，为0时标红*/
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        // 缺货数量
        if($(trArr[i]).find(".little-number").html() > 0){
            $(trArr[i]).find(".little-number")[0].style.color = "red";
        }
    }
    for(var j=0;j<trArr.length;j++){
        // 缺货数量
        if($(trArr[j]).find(".little-number")[0].style.color == "red"){
            $("#tableDiv").animate({scrollTop:$(trArr[j])[0].offsetTop},"fast");
            return;
        }
    }

}
/*判断是否全部选中*/
function isSelectAll() {
    var checkedArr = [];
    var selectAllInp = document.querySelectorAll(".spuId");
    for(var i=0;i<selectAllInp.length;i++){
        checkedArr.push(selectAllInp[i].checked);
    }
    console.log(checkedArr)
    if(checkedArr.indexOf(false)==-1){
        $("#select-all-inp")[0].checked = "checked";
    }else {
        $("#select-all-inp").attr("checked",false);
    }
}
/*复选框功能*/
function selectThis(el) {
    isSelectAll();
    getSelectLines();//计算购买数量和总金额
}
/*全选功能*/
function selectAll(el) {
    var selectAllInp = document.querySelectorAll(".spuId");
    for(var i=0;i<selectAllInp.length;i++){
        selectAllInp[i].checked = el.checked;
    }
    getSelectLines();//计算购买数量和总金额
}
/*校验库存*/
function checkCount(el){
    el.value=el.value.replace(/[^0-9]/ig,'');
    if(el.value == 0||el.value%Number($(el.parentElement.parentElement.parentElement).find(".mini-order").html())!=0){
        el.value = Number($(el.parentElement.parentElement.parentElement).find(".mini-order").html());
        if(Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= el.value){
            $(el.parentElement.parentElement.parentElement).find(".little-number").html("--");
            $(el.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
        }else {
            $(el.parentElement.parentElement.parentElement).find(".little-number").html(el.value - Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html()));
            $(el.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
        }
    }
    if(el.value>Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html())+Number($(el.parentElement.parentElement.parentElement).find(".virtual-stock").html())){
        el.value = Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html())+ Number($(el.parentElement.parentElement.parentElement).find(".virtual-stock").html());
        $(el.parentElement.parentElement.parentElement).find(".sub-total").html((Number(el.value)*Number($(el.parentElement.parentElement.parentElement).find(".price").html())).toFixed(2));
        if(Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= el.value){
            $(el.parentElement.parentElement.parentElement).find(".little-number").html("--");
            $(el.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
        }else {
            $(el.parentElement.parentElement.parentElement).find(".little-number").html(el.value - Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html()));
            $(el.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
        }
        getSelectLines();
        getGoodsDrafts();
    }else {
        var trArr = $("#datatable tr");
        for(var i=0;i<trArr.length;i++){
            $(trArr[i]).css({
                background:"white"
            })
        }
        $(el.parentElement.parentElement.parentElement).find(".sub-total").html((Number($(el.parentElement.parentElement.parentElement).find(".count")[0].firstChild.lastChild.value)*Number($(el.parentElement.parentElement.parentElement).find(".price").html())).toFixed(2));
        if(Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html()) >= Number($(el.parentElement.parentElement.parentElement).find(".count")[0].firstChild.lastChild.value)){
            $(el.parentElement.parentElement.parentElement).find(".little-number").html("--");
            $(el.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "#333";
        }else {
            $(el.parentElement.parentElement.parentElement).find(".little-number").html(Number($(el.parentElement.parentElement.parentElement).find(".count")[0].firstChild.lastChild.value) - Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html()));
            $(el.parentElement.parentElement.parentElement).find(".little-number")[0].style.color = "red";
        }
        getSelectLines();
        getGoodsDrafts();
    }
    // 预计出货日
    if(Number($(el.parentElement.parentElement.parentElement).find(".actual-stock").html())>=el.value){
        $(el.parentElement.parentElement.parentElement).find(".arrivalCycle").html(1);
    } else {
        $(el.parentElement.parentElement.parentElement).find(".arrivalCycle").html(Number($(el.parentElement.parentElement.parentElement).find(".arrival-cycle").html())+1);
    }
}
/*小计计算*/
function subtotal(count,price,el) {
    $(el.parentElement.parentElement.parentElement).find(".sub-total").html((count*price).toFixed(2));
}
/*获取全部选中的行以及计算购买数量和总额*/
var buyCount = 0;
var buyAmount = 0;
function getSelectLines(){
    buyCount = 0;
    buyAmount = 0;
    var trArr = $("#datatable tr");
    for (var i=0;i<trArr.length;i++){
        var dataLinesTd = $(trArr[i]).find("td");
        if(dataLinesTd[0].firstChild.checked == true){
            console.log($(trArr[i]).find(".count").find(".numberbar").find("input").val())
            buyCount = buyCount + Number($(trArr[i]).find(".count").find(".numberbar").find("input").val()); //数量
            buyAmount = buyAmount + Number($(trArr[i]).find(".sub-total").html());
        }
    }
    $("#amountMoney").html((buyAmount).toFixed(2));
    $("#buyCount").html(buyCount);
}
/*保存草稿时获取列表数据*/
function getGoodsDrafts() {
    tradeBoxItemsList = [];
    purchaseCount = 0;
    totalMoney = 0;
    var draftsPrice = 0;

    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        if($(trArr[i]).find(".price").html()=="-"){
            draftsPrice = 0;
        }else {
            draftsPrice = $(trArr[i]).find(".price").html();
        }
        tradeBoxItemsList.push({
            skuCode: $(trArr[i]).find(".sku-code").html(),
            skuName: $(trArr[i]).find(".sku-name").html(),
            purchaseCount: $(trArr[i]).find(".count").find(".numberbar").find("input").val(),
            miniOrder: $(trArr[i]).find(".mini-order").html(),
            salePrice: draftsPrice,
            virtualStock: $(trArr[i]).find(".virtual-stock").html(),
            arrivalCycle: $(trArr[i]).find(".arrivalCycle").html(),
            spuId: $(trArr[i]).find(".spu-id").html(),
            skuId: $(trArr[i]).find(".sku-id").html(),
            orderLimitType: $(trArr[i]).find(".order-limit-type").html(),
        });
        purchaseCount += Number($(trArr[i]).find(".count").find(".numberbar").find("input").val());
        totalMoney += Number(Number(draftsPrice)*Number($(trArr[i]).find(".count").find(".numberbar").find("input").val()));
    }
}
/*点击删除，删除订单*/
var deletBtn = "";//定义变量保存删除按钮this
function modaldemo(el) {
    deletBtn = el;
    $("#modal-demo").modal("show");
    // $.Huimodalalert('删除了',2000);
}
function getAllGoods() {
    /*获取所有添加的商品*/
    var afterDeletGoodsTr = [];
    /*获取table的行*/
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        console.log($(trArr[i]))
        console.log($(trArr[i]).find(".sub-total").html())

        afterDeletGoodsTr.push({
            sku_code: $(trArr[i]).find(".sku-code").html(),
            sku_name: $(trArr[i]).find(".sku-name").html(),
            sale_attri_value: $(trArr[i]).find(".sku-info").html(),
            origin: $(trArr[i]).find(".origin").html(),
            count: $(trArr[i]).find(".count").find(".numberbar").find("input").val(),
            unit: $(trArr[i]).find(".unit").html(),
            parts_number: $(trArr[i]).find(".parts-number").html(),
            mini_order: $(trArr[i]).find(".mini-order").html(),
            saleType: Number($(trArr[i]).find(".sale-type-code").html()),
            price: $(trArr[i]).find(".price").html(),
            sub_totle: $(trArr[i]).find(".sub-total").html(),
            actual_stock: $(trArr[i]).find(".actual-stock").html(),
            virtual_stock: $(trArr[i]).find(".virtual-stock").html(),
            arrivalCycle:$(trArr[i]).find(".arrivalCycle").html(),
            warehouse_name: $(trArr[i]).find(".warehouse-name").html(),
            helpcode: $(trArr[i]).find(".help-code").html(),
            spu_id: $(trArr[i]).find(".spu-id").html(),
            sku_id: $(trArr[i]).find(".sku-id").html(),
            order_limit_type: $(trArr[i]).find(".order-limit-type").html(),
            arrival_cycle: $(trArr[i]).find(".arrival-cycle").html(),
            checkedState: $($(trArr[i]).find("td")[0]).find("input")[0].checked,
        });
    }
    return afterDeletGoodsTr;
}
var delGoodsTr = [];//删除后的商品数据
function deleteSure() {
    $(deletBtn.parentElement.parentElement).remove();
    delGoodsTr = getAllGoods();
    console.log(delGoodsTr)
    renderTable(true);
    $("#modal-demo").modal("hide");
}
/*删除选中的商品*/
function deletSelect() {
    if($("#buyCount").html()!=0){
        $("#modal-delete").modal("show");
    }
}
function deleteSelectSure() {
    var afterDeletGoodsTr = [];
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        if($(trArr[i]).find("td")[0].firstElementChild.checked == true){
            trArr[i].remove();
        }else {
            afterDeletGoodsTr.push({
                sku_code: $(trArr[i]).find(".sku-code").html(),
                sku_name: $(trArr[i]).find(".sku-name").html(),
                sale_attri_value: $(trArr[i]).find(".sku-info").html(),
                origin: $(trArr[i]).find(".origin").html(),
                count: $(trArr[i]).find(".count").find(".numberbar").find("input").val(),
                unit: $(trArr[i]).find(".unit").html(),
                parts_number: $(trArr[i]).find(".parts-number").html(),
                mini_order: $(trArr[i]).find(".mini-order").html(),
                saleType: Number($(trArr[i]).find(".sale-type-code").html()),
                price: $(trArr[i]).find(".price").html(),
                sub_totle: $(trArr[i]).find(".sub-totle").html(),
                actual_stock: $(trArr[i]).find(".actual-stock").html(),
                virtual_stock: $(trArr[i]).find(".virtual-stock").html(),
                arrivalCycle:$(trArr[i]).find(".arrivalCycle").html(),
                warehouse_name: $(trArr[i]).find(".warehouse-name").html(),
                helpcode: $(trArr[i]).find(".help-code").html(),
                spu_id: $(trArr[i]).find(".spu-id").html(),
                sku_id: $(trArr[i]).find(".sku-id").html(),
                order_limit_type: $(trArr[i]).find(".order-limit-type").html(),
                arrival_cycle: $(trArr[i]).find(".arrival-cycle").html(),
                checkedState: $($(trArr[i]).find("td")[0]).find("input")[0].checked,
            });
        }
    }
    delGoodsTr = afterDeletGoodsTr;
    renderTable(true);
    $("#amountMoney").html("0.00");
    $("#buyCount").html(0);
    $("#modal-delete").modal("hide");
    isCanDelect = false;
    $("#select-all-inp").attr("checked",false);
}
/*点击确定跳至商品搜索页*/
function goSearchGoods() {
    if($("#vueBox").css("display") == "block"){
        /*当改变地址时设置cityId的值*/
        cityCode = $("#cityCode").html();
    }
    if(cityCode == ""||$("#orderCode select").val()==""){
        $.Huimodalalert('请检查客户信息是否填写完全',2000);
    }else {
        if($("#skuId").val() =="" && $("#skuName").val() == "" && $("#helpCode").val() == ""){
            $.Huimodalalert('请至少添加一个搜索条件',2000);
        }else {
            var goodsCount = 0;
            var trArr = $("#datatable tr");
            for(var i=0;i<trArr.length;i++) {
                if ($(trArr[i]).find("td")[0].firstElementChild.checked == true) {
                    goodsCount += 1;
                }
            }
            var goodsTr = getAllGoods();
            console.log(goodsTr)
            sessionStorage.setItem("goodsTr",JSON.stringify(goodsTr));
            var skuName_base64 = Base64.encode($("#skuName").val());
            var skuId_base64 = Base64.encode($("#skuId").val());
            var helpCode_base64 = Base64.encode($("#helpCode").val());
            var index = layer.open({
                type: 2,
                title: "商品查询",
                content: "searchGoods.html?skuId="+skuId_base64+"&skuName="+skuName_base64+"&helpCode="+helpCode_base64+"&cityId=" + cityCode + "&goodsCount=" + goodsCount + "&customerId=" + $("#orderCode select").find("option:selected")[0].dataset.cusid+ "&warehouseCode=" + warehouseCode
            });
            layer.full(index);
        }
    }


}
/*点击搜索列表商品*/
function searchGoodsList() {
    //搜索值
    var skuCode = $("#skuId").val();
    var skuName = $("#skuName").val();
    var helpCode = $("#helpCode").val().toUpperCase();
    // table标签tr
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        $(trArr[i]).css({
            background:"white"
        })
    }
    var searchResult  = [];
    for(var i=0;i<trArr.length;i++){
        if(skuCode!="" && skuName!="" && helpCode !=""){
            if($(trArr[i]).find(".sku-name").html().indexOf(skuName,0) != -1 && $(trArr[i]).find(".sku-code").html().indexOf(skuCode,0) != -1 && $(trArr[i]).find(".arrivalCycle").html().indexOf(helpCode,0) != -1){
                searchResult.push(i);
                $(trArr[i]).css({
                    background: "#e8f1fb"
                })
            }
        }if(skuName!="" && helpCode !="" && skuCode==""){
            if($(trArr[i]).find(".sku-name").html().indexOf(skuName,0) != -1 && $(trArr[i]).find(".help-code").html().indexOf(helpCode,0) != -1){
                searchResult.push(i);
                $(trArr[i]).css({
                    background: "#e8f1fb"
                })
            }
        }if(skuCode!="" && helpCode !="" && skuName==""){
            if($(trArr[i]).find(".sku-code").html().indexOf(skuName,0) != -1 && $(trArr[i]).find(".help-code").html().indexOf(helpCode,0) != -1){
                searchResult.push(i);
                $(trArr[i]).css({
                    background: "#e8f1fb"
                })
            }
        }if(skuCode!="" && skuName!="" && helpCode==""){
            if($(trArr[i]).find(".sku-name").html().indexOf(skuName,0) != -1 && $(trArr[i]).find(".sku-code").html().indexOf(skuCode,0) != -1){
                searchResult.push(i);
                $(trArr[i]).css({
                    background: "#e8f1fb"
                })
            }
        }if(skuCode!="" && skuName=="" && helpCode==""){
            if($(trArr[i]).find(".sku-code").html().indexOf(skuCode,0) != -1){
                searchResult.push(i);
                $(trArr[i]).css({
                    background: "#e8f1fb"
                })
            }
        }if(helpCode !=""&&skuCode=="" && skuName==""){
            if($(trArr[i]).find(".help-code").html().indexOf(helpCode,0) != -1){
                searchResult.push(i);
                $(trArr[i]).css({
                    background: "#e8f1fb"
                })
            }
        }if(skuName!=""&&skuCode=="" && helpCode==""){
            if($(trArr[i]).find(".sku-name").html().indexOf(skuName,0) != -1){
                searchResult.push(i);
                $(trArr[i]).css({
                    background: "#e8f1fb"
                })
            }
        }
    }
    if(searchResult.length!=0){
        $("#tableDiv").animate({scrollTop:$(trArr[searchResult[0]])[0].offsetTop},"fast"); //定位tr
    }
}
/*点击商品名称跳转至sku详情*/
function goToGoodsDetail(el) {
    var spuId = $(el.parentElement).find(".spu-id").html();
    var skuId = $(el.parentElement).find(".sku-id").html();
    var index = layer.open({
        type: 2,
        title: "Code详情",
        content: "../../goods/product.html?spu_Id="+ spuId
    });
    layer.full(index);
}
/*点击保存草稿*/
function goDrafts() {
    if($("#vueBox").css("display") == "block"){
        /*当改变地址时设置四级地址的值*/
        provinceCode = $("#provinceCode").html();
        cityCode = $("#cityCode").html();
        districtCode = $("#countyCode").html();
        streetCode = $("#villageCode").html();
        provinceId = $("#provinceId").html();
        cityId = $("#cityId").html();
        districtId = $("#countyId").html();
        streetId = $("#villageId").html();
        provinceName = $("#vueProvinceName").html();
        cityName = $("#vueCityName").html();
        districtName = $("#vueCountyName").html();
        if($("#vueVillageName").html() == ""){
            streetName = " ";
            streetId = 0;
        }else {
            streetName = $("#vueVillageName").html();
        }
    }else {
        if(historyProvinceCode!=""){
            provinceCode= historyProvinceCode;
            cityCode= historyCityCode;
            districtCode = historyCountyCode;
            streetCode = historyVillageCode;
            provinceId = historyProvinceId;
            cityId = historyCityId;
            districtId = historyCountyId;
            streetId = historyVillageId;
        }
        provinceName = $("#provinceName").html();
        cityName = $("#cityName").html();
        districtName = $("#countyName").html();
        if($("#villageName").html() == ""){
            streetName = " ";
            streetId = 0;
        }else {
            streetName = $("#villageName").html();
        }
    }
    /* if (streetId == 0){
         streetId = "";
     }*/
    var draftsData = {
        "boxId": boxId,
        "labelUuid": labelUuid,
        "createUserId": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,  //创建用户id
        "createUserName": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,  //创建用户名称
        "custCompanyAddress": $("#address").html(),  //客户公司地址
        "customerId": $("#orderCode select").find("option:selected")[0].dataset.cusid, //客户id
        "customerLoginAccount": $("#orderCode select").find("option:selected").text(),  //客户登录帐号
        "customerName": $("#cusNameInfo").html(),  // 客户名称
        "customerCode": $("#orderCode select").find("option:selected")[0].dataset.code,
        "accountType": $("#orderCode select").find("option:selected")[0].dataset.accounttype,
        "memberId": $("#orderCode select").val(), //会员id
        "warehouseId":warehouseCode,
        "addressId":ship_add_id,
        "provinceCode": provinceCode,  //配送省code provinceId
        "cityCode": cityCode,  //配送城市code
        "districtCode": districtCode, //配送区code
        "streetCode": streetCode, //配送街code
        "provinceId":provinceId,
        "cityId": cityId,
        "districtId": districtId,
        "streetId": streetId,
        "provinceName": provinceName,//配送区域省Name
        "cityName": cityName,//配送区域市Name
        "districtName": districtName,//配送区域区Name
        "streetName": streetName,//配送区域街Name
        "purchaseCount": purchaseCount, //购买商品总数量
        "totalMoney": totalMoney.toFixed(2), //购买商品总金额(精确到2位)
        "tradeBoxItemsList": tradeBoxItemsList,//购买商品集合
    }
    $.ajax({
        contentType:"application/json",
        type: "POST",
        url: root.replaceInter.replace_saveTradeBox,
        cache: false,  //禁用缓存
        dataType: "json",
        data: JSON.stringify(draftsData),
        success: function (result) {
            if(result.errorCode == 0){
                $.Huimodalalert('添加草稿箱成功,请在草稿箱查看',2000);
            }else if(result.errorCode == 55){
                var trArr = $("#datatable tr");
                for(var i=0;i<trArr.length;i++){
                    for(var j=0;j<result.goodChangeSkuVoList.length;j++){
                        if($(trArr[i]).find(".sku-id").html() == result.goodChangeSkuVoList[j].skuId){
                            trArr[i].style.background = "#ffe7e7";
                        }
                    }
                }
            }else if(result.errorCode == 22){
                $.Huimodalalert("请添加商品",2000);
            }else {
                $.Huimodalalert("添加失败请联系管理员",2000);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
        }
    });
}
/*判断是否存在缺货商品*/
function out_of_stock_fn() {
    out_of_stock = false;
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        if($(trArr[i]).find("td")[0].firstElementChild.checked == true){
            // 缺货数量
            if($(trArr[i]).find(".little-number")[0].style.color == "red") {
                out_of_stock = true;
                $("#noStocker").modal("show");
                $("#tableDiv").animate({scrollTop: $(trArr[i])[0].offsetTop}, "fast");
                return;
            }
        }
    }
    if(!out_of_stock){
        goConFirmOrder();
        $("#noStocker").modal("hide");
    }
}
function setRedFn() {
    /*判断缺货数量是否为0，为0时标红*/
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        if($(trArr[i]).find("td")[0].firstElementChild.checked == true){
            // 缺货数量
            if($(trArr[i]).find(".little-number").html() > 0){
                trArr[i].style.background = "#ffe7e7";
                $(trArr[i]).find(".little-number")[0].style.color = "red";
            }
        }
    }
    for(var j=0;j<trArr.length;j++){
        if($(trArr[i]).find("td")[0].firstElementChild.checked == true){
            // 缺货数量
            if($(trArr[j]).find(".little-number")[0].style.color == "red"){
                $("#tableDiv").animate({scrollTop:$(trArr[j])[0].offsetTop},"fast");
                return;
            }
        }
    }
}
/*点击下一步跳至确认订单*/
var isIng = false;
function goConFirmOrder() {
    if(isIng){
        // layer.msg('请勿重复点击！');
        return false;
    }
    isIng = true;
    $("#noStocker").modal("hide");
    /*点击下一步时获取当前选中所有商品的数据以及地址区域*/
    var afterDeletGoodsTr = [];
    var purchaseCount = 0;
    var trArr = $("#datatable tr");
    for(var i=0;i<trArr.length;i++){
        if($(trArr[i]).find("td")[0].firstElementChild.checked == true){
            purchaseCount += Number($(trArr[i]).find(".count").find(".numberbar").find("input").val());
            afterDeletGoodsTr.push({
                boxRowId: $(trArr[i]).find("td")[0].lastChild.innerHTML,
                skuCode: $(trArr[i]).find(".sku-code").html(),
                buyyerCount: $(trArr[i]).find(".count").find(".numberbar").find("input").val(),
                salePrice: $(trArr[i]).find(".price").html(),
                spuId: $(trArr[i]).find(".spu-id").html(),
                skuId: $(trArr[i]).find(".sku-id").html(),
                saleType: Number($(trArr[i]).find(".sale-type-code").html()),
            });
        }
    }

    /*跳至确认订单页面时的地址区域参数*/
    if($("#vueBox").css("display") == "block"){
        /*当改变地址时设置四级地址的值*/
        if($("#vueVillageName").html() == ""){
            var streetName = " ";
            var streetId= "0";
        }else {
            var streetName = $("#vueVillageName").html();
        }
        var customerInfo = {
            boxId: boxId,
            createUserId:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            createUserName:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
            warehouseId:warehouseCode,
            inquiryWarehouseId:inquiryWarehouseId,
            ship_add_id:ship_add_id,
            provinceCode:$("#provinceCode").html(),
            cityCode: $("#cityCode").html(),
            districtCode: $("#countyCode").html(),
            streetCode: $("#villageCode").html(),
            provinceId:$("#provinceId").html(),
            cityId: $("#cityId").html(),
            districtId: $("#countyId").html(),
            streetId: $("#villageId").html(),
            provinceName: $("#vueProvinceName").html(),
            cityName: $("#vueCityName").html(),
            districtName: $("#vueCountyName").html(),
            streetName: streetName,
            customerName: $("#cusNameInfo").html(),
            customerLoginAccount: $("#orderCode select").find("option:selected").text(),
            customerId: $("#orderCode select").find("option:selected")[0].dataset.cusid,
            customerCode: $("#orderCode select").find("option:selected")[0].dataset.code,
            accountType: $("#orderCode select").find("option:selected")[0].dataset.accounttype,
            neetAudit: $("#orderCode select").find("option:selected")[0].dataset.neetaudit,
            all_author_single_user: $("#orderCode select").find("option:selected")[0].dataset.all_author_single_user,
            custCompanyAddress: $("#address").html(),
            memberId: $("#orderCode select").val(),
            device_platform:"pc",
            purchaseCount: purchaseCount,
            totalMoney: $("#amountMoney").html(),
            out_of_stock:out_of_stock,
        }
    }else {
        if(historyProvinceCode!=""){
            provinceCode = historyProvinceCode;
            cityCode = historyCityCode;
            districtCode = historyCountyCode;
            streetCode = historyVillageCode;
            provinceId = historyProvinceId;
            cityId = historyCityId;
            districtId = historyCountyId;
            streetId = historyVillageId;
        }
        if($("#villageName").html() == ""){
            var streetName = " ";
            streetId = 0;
        }else {
            var streetName = $("#villageName").html();
        }
        var customerInfo = {
            boxId: boxId,
            createUserId:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            createUserName:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
            warehouseId: warehouseCode,
            inquiryWarehouseId:inquiryWarehouseId,
            ship_add_id:ship_add_id,
            provinceCode: provinceCode,
            cityCode: cityCode,
            districtCode:districtCode,
            streetCode:streetCode,
            provinceId:provinceId,
            cityId: cityId,
            districtId: districtId,
            streetId: streetId,
            provinceName: $("#provinceName").html(),
            cityName: $("#cityName").html(),
            districtName: $("#countyName").html(),
            streetName: streetName,
            customerName: $("#cusNameInfo").html(),
            customerLoginAccount: $("#orderCode select").find("option:selected").text(),
            customerId: $("#orderCode select").find("option:selected")[0].dataset.cusid,
            customerCode: $("#orderCode select").find("option:selected")[0].dataset.code,
            accountType: $("#orderCode select").find("option:selected")[0].dataset.accounttype,
            neetAudit: $("#orderCode select").find("option:selected")[0].dataset.neetaudit,
            all_author_single_user: $("#orderCode select").find("option:selected")[0].dataset.all_author_single_user,
            custCompanyAddress: $("#address").html(),
            memberId: $("#orderCode select").val(),
            device_platform:"pc",
            purchaseCount: purchaseCount,
            totalMoney: $("#amountMoney").html(),
            out_of_stock:out_of_stock,
        }
    }

    customerInfo.skuModelList = {"666":afterDeletGoodsTr};
    if(afterDeletGoodsTr.length!=[]){
        $.ajax({
            contentType: 'application/json',
            url: root.replaceInter.replace_checkCartProduct,
            // url: 'https://'+ window.location.host +'/api/admin/atrade/adminTrade/checkCartProduct',

            cache: false, //禁用缓存
            type: "POST",
            data: JSON.stringify(customerInfo),
            success: function(data) {
                isIng = false;
                sessionStorage.setItem("customerInfo",JSON.stringify(customerInfo));  //账户信息
                data = JSON.parse(data);
                if(data.errorCode == "0"){
                    var index = layer.open({
                        type: 2,
                        title: "确认订单",
                        content: "confirmOrder.html"
                    });
                    layer.full(index);
                }else if(data.errorCode == 61){
                    setTrRed("",JSON.stringify(data));
                    var canGoNext = false;
                    for(var i=0;i<data.abnormalProducts.length;i++){
                        if(data.abnormalProducts[i].code==70){
                            canGoNext = true;
                        }else {
                            canGoNext = false;
                            return;
                        }
                    }
                    if(canGoNext){
                        var index = layer.open({
                            type: 2,
                            title: "确认订单",
                            content: "confirmOrder.html"
                        });
                        layer.full(index);
                    }
                    $("#select-all-inp").attr("checked",false);
                }else if(data.errorCode == 22){
                    $.Huimodalalert("请添加商品",2000);
                }else {
                    $.Huimodalalert(data.tip,2000);
                }
            }
        });
    } else {
        $.Huimodalalert("请添加商品",2000);
        isIng = false;
    }
}
/*无搜索结果显示函数*/
function noGoods() {
    $.Huimodalalert("无搜索结果",2000);
}